/*
 *  Copyright 2012 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.odg.dg;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.opu.odg.dg.incomingdata.CustomContentDescription;
import org.opu.odg.dg.incomingdata.GlobalVariables;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementMap;
import org.simpleframework.xml.Root;

/**
 *
 * @author yura
 */
@Root(name="generationSettings")
public class GenerationSettings implements Serializable {

    /*
     * This class is some kind of start.xml for document generation process.
     */

    @Attribute
    private Integer templateId;

    @Element
    private GlobalVariables variables;

    @ElementMap(entry="custom", valueType=CustomContentDescription.class, attribute=true)
    private HashMap<String, CustomContentDescription> descriptions;

    private GenerationSettings() {
        // for simple freamework
    }

    public GenerationSettings(Integer templateId, GlobalVariables variables,
            Map<String, CustomContentDescription> descriptions) {
        this.templateId = templateId;
        this.variables = variables;
        this.descriptions = new HashMap<String, CustomContentDescription>(descriptions);
    }

    public Map<String, CustomContentDescription> getDescriptions() {
        return descriptions;
    }

    public Integer getTemplateId() {
        return templateId;
    }

    public GlobalVariables getVariables() {
        return variables;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final GenerationSettings other = (GenerationSettings) obj;
        if (this.templateId != other.templateId && (this.templateId == null || !this.templateId.equals(other.templateId))) {
            return false;
        }
        if (this.variables != other.variables && (this.variables == null || !this.variables.equals(other.variables))) {
            return false;
        }
        if (this.descriptions != other.descriptions && (this.descriptions == null || !this.descriptions.equals(other.descriptions))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.templateId != null ? this.templateId.hashCode() : 0);
        hash = 79 * hash + (this.variables != null ? this.variables.hashCode() : 0);
        hash = 79 * hash + (this.descriptions != null ? this.descriptions.hashCode() : 0);
        return hash;
    }

}
